/*
 * @lc app=leetcode.cn id=1464 lang=javascript
 *
 * [1464] 数组中两元素的最大乘积
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxProduct = function (nums) {
  let [max, max2] = nums;
  if (max < max2) {
    [max, max2] = [max2, max];
  }
  for (let i = 2; i < nums.length; i++) {
    if (nums[i] > max) {
      max2 = max;
      max = nums[i];
      continue;
    }
    if (nums[i] > max2) {
      max2 = nums[i];
    }
  }
  return (max - 1) * (max2 - 1);
};
// @lc code=end

